package com.flower8.service.impl;

import com.flower8.dao.PlusDao;
import com.flower8.service.PlusService;
import com.flower8.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: plus会员实现类
 * @Author: tanglin
 * @Date: 2020/3/26 15:16
 * @Version: 1.0
 */
@Service
public class PlusServiceImpl implements PlusService {

    @Autowired
    private PlusDao plusDao;

    /**
     * 查询plus会员套餐列表
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public List<Map> getPlusGoodsList(PageData pd) throws Exception {
        return plusDao.getPlusGoodsList(pd);
    }

    /**
     * 查询plus会员套餐列表数量
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int getPlusGoodsCount(PageData pd) throws Exception {
        return plusDao.getPlusGoodsCount(pd);
    }

    /**
     * 根据plus会员套餐ID查询
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public Map getPlusGoodsById(long id) throws Exception {
        return plusDao.getPlusGoodsById(id);
    }

    /**
     * 修改plus会员套餐
     * @param param
     * @throws Exception
     */
    @Override
    @Transactional
    public void updPlusGoods(Map param) throws Exception {
        plusDao.updPlusGoods(param);
    }

    /**
     * 新增plus会员套餐
     * @param param
     * @throws Exception
     */
    @Override
    @Transactional
    public void addPlusGoods(Map param) throws Exception {
        plusDao.addPlusGoods(param);

        //设置ios内购id
        Map updMap = new HashMap();
        updMap.put("id", param.get("id"));
        updMap.put("iosId", "com.bajiaohua.credit.help.product"+param.get("id").toString());
        plusDao.updPlusGoods(updMap);
    }

    /**
     * 删除plus会员套餐
     * @param id
     * @throws Exception
     */
    @Override
    @Transactional
    public void delPlusGoods(long id) throws Exception {
        plusDao.delPlusGoods(id);
    }
}
